<!-- 查看团队成员信息 -->
<template>
  <a-modal
    :visible="viewCenterModalVisible"
    title="查看人员信息"
    :footer="null"
    width="80%"
    @cancel="handleCancel(0)">
    <a-descriptions title="基本信息" bordered>
      <a-descriptions-item label="人员编号">{{ viewCenterMemberDetail.researchNo }}</a-descriptions-item>
      <a-descriptions-item label="角色">{{ viewCenterMemberDetail.roleName }}</a-descriptions-item>
      <a-descriptions-item label="组织">{{ hospitalNameProp }}</a-descriptions-item>
      <a-descriptions-item label="姓名">{{ viewCenterMemberDetail.name }}</a-descriptions-item>
      <a-descriptions-item label="手机">{{ viewCenterMemberDetail.phone }}</a-descriptions-item>
      <a-descriptions-item label="邮箱">{{ viewCenterMemberDetail.email }}</a-descriptions-item>
      <a-descriptions-item label="身份证">{{ viewCenterMemberDetail.idCard }}</a-descriptions-item>
      <a-descriptions-item label="是否审核人">{{ viewCenterMemberDetail.isCheck == 1 ? '是' : '否' }}</a-descriptions-item>
      <a-descriptions-item label="中心负责人">{{ viewCenterMemberDetail.mainResearch == 1 ? '是' : '否' }}</a-descriptions-item>
      <a-descriptions-item label="邀请状态">{{ viewCenterMemberDetail.authStatus | enumValueByKey($const.CENTER_MEMBER_STATUS) }}</a-descriptions-item>
    </a-descriptions>
    <div v-if="$auth('PROJECT.PROJECT_RESEARCH_MEMBER_EDIT') || auditPmsVisible">
      <div>
        <a-descriptions title="是否设为中心负责人" :style="{ marginTop: '32px' }" />
        <a-radio-group v-model="viewCenterMemberDetail.mainResearch">
          <a-popconfirm
            :title="titleShow"
            ok-text="确定"
            cancel-text="取消"
            @confirm="clickConfirm(1)">
            <a-radio :value="1">是</a-radio>
          </a-popconfirm>
          <a-popconfirm
            :title="disTitleShow"
            ok-text="确定"
            cancel-text="取消"
            @confirm="clickConfirm(0)">
            <a-radio :value="0">否</a-radio>
          </a-popconfirm>
        </a-radio-group>
      </div>
      <div>
        <a-descriptions title="是否设为审核人" :style="{ marginTop: '32px' }" />
        <a-radio-group v-model="viewCenterMemberDetail.isCheck">
          <a-popconfirm
            title="设为审核人？"
            ok-text="确定"
            cancel-text="取消"
            @confirm="setApprover(1)">
            <a-radio :value="1">是</a-radio>
          </a-popconfirm>
          <a-popconfirm
            title="设为非审核人？"
            ok-text="确定"
            cancel-text="取消"
            @confirm="setApprover(0)">
            <a-radio :value="0">否</a-radio>
          </a-popconfirm>
        </a-radio-group>
      </div>
      <div v-if="viewCenterMemberDetail.authStatus == 3">
        <a-descriptions title="审核意见" :style="{ marginTop: '32px' }" />
        <a-textarea
          :auto-size="{ minRows: 5 }"
          placeholder="审批意见：若接受则可不填写"
          allow-clear
          v-model="commitData.refuseReason"
        />
        <div style="margin-top: 20px">
          <a-button type="primary" @click="clickSubject(1)" style="margin-right: 20px">同意</a-button>
          <a-button @click="clickSubject(2)">拒绝</a-button>
        </div>
      </div>
    </div>
  </a-modal>
</template>

<script>
import monitor from '@/utils/monitor'
import viewCenterMemberModal from '@/monitor/views/overview/detail/responsible/components/members/viewCenterMemberModal'

import { getCenterDetail, updateCenterMember, updateMainRes, updateApprover } from '@/api/overview/member'
import { getInfo } from '@/api/login'
const watch = monitor(viewCenterMemberModal)

export default {
  props: {
    viewCenterModalVisible: {
      type: Boolean,
      default: false
    },
    viewCenterMemberDetail: {
      type: Object,
      default: () => {
        return {}
      }
    },
    // 将选择的医院传递过来用于展示
    hospitalNameProp: {
      type: String,
      default: ''
    },
    mProId: {
      type: [Number, String],
      default: null
    }
  },
  data () {
    return {
      commitData: {},
      titleShow: null,
      disTitleShow: null,
      statusValue: null,
      auditPmsVisible: false
    }
  },
  created () {
  },
  watch: {
    viewCenterModalVisible (e) {
      if (e) {
        if (this.mProId) {
          getInfo({ proId: this.mProId }).then(res => {
            this.auditPmsVisible = !!(res.pms && res.pms.indexOf('PROJECT_RESEARCH_MEMBER_EDIT') >= 0)
          })
        }
      }
    }
  },
  methods: watch({
    // 请求详情筛选负责人name
    getCenterDetail (val, label) {
      getCenterDetail({ resId: val })
        .then(res => {
          console.log(res, '**************')
          const target = res.detailsList.content.find(item => item.mainResearch === 1)
          if (target) {
            this.titleShow = '当前负责人为' + target.name + '是否更换负责人？'
          } else {
            this.titleShow = '是否将' + this.viewCenterMemberDetail.name + '设为当前项目负责人？'
          }
          this.disTitleShow = '是否将' + this.viewCenterMemberDetail.name + '取消中心负责人？'
          if (label) {
            updateMainRes({ id: this.viewCenterMemberDetail.id, mainResearch: this.statusValue, researchId: this.viewCenterMemberDetail.researchId, proId: this.viewCenterMemberDetail.proId })
              .then(res => {
                this.viewCenterMemberDetail.mainResearch = this.statusValue
                this.$message.success('负责人更换成功')
                this.handleCancel(1)
              })
              .catch(() => {})
          }
        })
        .catch(() => {})
    },
    clickConfirm (val) {
      this.statusValue = val
      this.getCenterDetail(this.viewCenterMemberDetail.researchId, 1)
    },
    // 设为审核人
    setApprover (val) {
      updateApprover({ id: this.viewCenterMemberDetail.id, proId: this.viewCenterMemberDetail.proId, isCheck: val })
        .then(res => {
          this.$message.success('审核人修改成功')
          this.handleCancel(1)
        })
    },
    // 点击同意/拒绝
    clickSubject (val) {
      this.approvalMember()
      if (val === 2) {
        if (this.commitData.refuseReason === null || this.commitData.refuseReason === undefined || this.commitData.refuseReason === '') {
          this.$message.error('请填写拒绝理由')
          return false
        }
      }
      this.commitData.id = this.viewCenterMemberDetail.id
      this.commitData.authStatus = val
      updateCenterMember({ ...this.commitData })
        .then(res => {
          this.$message.success('更改成功')
          this.handleCancel(1)
        })
        .catch(() => {})
    },
    // 点击取消对话框消失
    handleCancel (val) {
      this.$emit('closeViewCenterModal', val)
    },
    // 成员审核埋点
    approvalMember () {}
  })
}
</script>
<style scoped lang="scss">

</style>
